package com.codeape.number.ui.fragment;

import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.codeape.number.R;
import com.codeape.number.entity.Result;

public class YaociTab extends Fragment {

    private View mInflaterView;

    private TextView mGuaciTextView;

    private GestureDetector mGestureDetector;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        if (null != mInflaterView && null != mInflaterView.getParent()) {
            ViewGroup parent = (ViewGroup) mInflaterView.getParent();
            parent.removeView(mInflaterView);
            return mInflaterView;
        }

        mInflaterView = inflater.inflate(R.layout.layout_pager, container, false);

        Result result = this.requireActivity().getIntent().getParcelableExtra("result");

        mGuaciTextView = mInflaterView.findViewById(R.id.tvContent);

        assert result != null;
        mGuaciTextView.setText(String.format("%s卦，变爻为%s\n\n%s\n\n解读\n%s", result.getGuaName(), result.getYaoNumber(), result.getYaoCi(), result.getYaoCiExplain()));

        mGuaciTextView.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
        mGuaciTextView.setTextIsSelectable(true);
        mGestureDetector = new GestureDetector(this.getActivity(), new GestureDetector.SimpleOnGestureListener() {
        });
        mGestureDetector.setOnDoubleTapListener(null);

        return mInflaterView;

    }

}